<!-- 待办事项 -->
<template>
  <div>
    <div class="page-list">
      <div class="todo-item" v-for="item in pageList" :key="item.id" @click="goToPage(item)">
        <img class="todo-img" :src="item.imgUrl" />
        <div class="todo-item-centent">{{ item.name }}</div>
      </div>
    </div>
    <HomeCard title="待办事项">
      <template v-slot:content>
        <div class="todo-list">
          <div class="todo-item mt-20" v-for="item in todoList" :key="item.id" @click="goToPage(item)">
            <Badge :count="item.userTodoTypeCount">
              <img class="todo-img" :src="item.imgUrl" />
            </Badge>
            <div class="todo-item-centent">{{ item.userTodoTypeName }}</div>
          </div>
        </div>
      </template>
    </HomeCard>
  </div>
</template>

<script type="text/javascript">
import HomeCard from "@/pages/components/homeCard/index.vue";
import { getMyTodo, clearTodo } from "@/api/home.js";

import img_1 from '../../assets/icon/icon-home-1.png'
import img_2 from '../../assets/icon/icon-home-2.png'
import img_3 from '../../assets/icon/icon-home-3.png'
import img_4 from '../../assets/icon/icon-home-4.png'
import img_5 from '../../assets/icon/icon-home-5.png'
import img_6 from '../../assets/icon/icon-home-6.png'
import img_7 from '../../assets/icon/icon-home-7.png'
import img_8 from '../../assets/icon/icon-home-8.png'


export default {
  name: "todo-page",
  components: {
    HomeCard,
  },
  data () {
    return {
      // userTodoTypeEnum: {
      // },
      todoList: [
        {
          id: "1",
          userTodoTypeName: "经营信息跟踪",
          userTodoTypeCount: 0,
          imgUrl: img_4,
          path: '/businessInformationTrack',
          userTodoType: 'BusinfoFeedbackNotifyCount'
        },
        {
          id: "2",
          userTodoTypeName: "经营信息预警",
          userTodoTypeCount: 0,
          imgUrl: img_5,
          path: '/businessInformationWarning',
          userTodoType: 'BusinfoForewarningNotifyCount'
        },
        {
          id: "3",
          userTodoTypeName: "人员管理",
          userTodoTypeCount: 0,
          imgUrl: img_6,
          path: '/organizationManage',
          userTodoType: 'UserJoinCompanyNotifyCount'
        },
        {
          id: "4",
          userTodoTypeName: "我的企业",
          userTodoTypeCount: 0,
          imgUrl: img_7,
          path: '/myEnterprise',
          userTodoType: 'CompanyAuditNotifyCount'
        },
        {
          id: "5",
          userTodoTypeName: "经营信息接收",
          userTodoTypeCount: 0,
          imgUrl: img_8,
          path: '/businessInformationReceive',
          userTodoType: 'BusinfoReceiveNotifyCount'
        },
        {
          id: "6",
          userTodoTypeName: "经营信息审核",
          userTodoTypeCount: 0,
          imgUrl: img_2,
          path: '/myBusinessInfo',
          userTodoType: 'BusinfoAuditNotifyCount'
        },
      ],
      pageList: [
        {
          id: "1",
          name: "发布经营信息",
          imgUrl: img_1,
          path: '/publishBusinessInfo'
        },
        {
          id: "2",
          name: "发布信息查询",
          imgUrl: img_2,
          path: '/myBusinessInfo'
        },
        {
          id: "3",
          name: "经营信息一张图",
          imgUrl: img_3,
          path: '/businessInformationMap'
        },
      ],
    };
  },
  async created () {
    const res = await getMyTodo({})
    this.todoList.forEach(item => {
      res.forEach(it => {
        if (item.userTodoType === it.userTodoType) {
          item.userTodoTypeCount = it.userTodoTypeCount
        }
      })
    })
  },
  methods: {
    async goToPage ({ path, userTodoType, userTodoTypeCount }) {
      this.$router.push({ path })

      if (!userTodoType || !userTodoTypeCount) return
      await clearTodo({ userTodoType, clearCount: userTodoTypeCount })
    }
  },
};
</script>

<style lang="less" scoped>
.badge {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  display: inline-block;
  img {
    display: block;
    width: 52px;
  }
}

.mt-20 {
  margin-top: 20px;
}
.page-list {
  padding: 20px 0px;
  margin-bottom: 20px;
  border-radius: 6px;
}

.todo-list {
  margin: 0 -20px;
}

.todo-list,
.page-list {
  display: flex;
  flex-wrap: wrap;
  font-weight: 500;
  cursor: pointer;
  background-color: #fff;

  .todo-img {
    width: 50px;
    height: 50px;
  }
}

.todo-item {
  width: 33%;
  text-align: center;
}
</style>
